<?php

/**
* 万人车汇支付类
*/

namespace app\index\controller;

class WchPay extends \think\Controller
{
  protected $driver = ''; //支付平台, alipay, wechat
  protected $gateway = ''; //支付网关，网页支付，app支付等
  protected $pdata = ''; //自定义支付数据, 如 {"data":{"out_trade_no":"12345678", "userid":"654321"}, "openid":"asdfgh"}

  public function __construct(){
    $this->driver = $_GET['driver'] ? $_GET['driver'] : '';
    $this->gateway = $_GET['gateway'] ? $_GET['gateway'] : '';
    $this->pdata = $_GET['pdata'] ? $_GET['pdata'] : '';

    // $driver, $gateway, $pdata 均不允许为空
    if (empty($this->driver) || empty($this->pdata) || empty($this->pdata)){
      return "params empty";
    }
  }

  //支付入口
  public function pay(){
    $class = 'app\index\controller\\'. $this->driver . '\\' . ucfirst($this->driver) . ucfirst($this->gateway);
    $pay = new $class($this->pdata);

    return json_encode($pay->pay());
  }

  //退款入口
  public function refund(){

  }

}
